<template>
	<view style=" min-height:100vh;background-color: white;padding: 20rpx;padding-bottom: 40rpx;">
		<fui-form labelSize="26rpx" ref="form" labelWidth="180">
			<fui-form-item :padding='["30rpx",0]' bottomBorder>
				<fui-input size="26" v-model="formData.title" :borderBottom="false" :padding="[0]"
					placeholder="请输入招聘标题"></fui-input>
			</fui-form-item>
			<fui-form-item :padding='["30rpx",0]' bottomBorder label="工作描述:">
				<template v-slot:vertical>
					<fui-textarea maxlength="-1" :padding="['32rpx','0rpx']" :border-bottom="false" :border-top="false"
						placeholder="请输入工作详细描述..." v-model="formData.descr"></fui-textarea>
				</template>
			</fui-form-item>
			<fui-form-item :padding='["30rpx",0]' bottomBorder label="招聘性质:">
				<fui-input size="26" v-model="formData.nature" :borderBottom="false" :padding="[0]"
					placeholder="请输入招聘性质"></fui-input>
			</fui-form-item>
			<fui-form-item :padding='["30rpx",0]' bottomBorder label="工资形式:">

				<fui-input size="26" v-model="formData.wagesType" disabled :borderBottom="false" @click="show=true"
					:padding="[0]" placeholder="请选择工资形式"></fui-input>


				<fui-picker linkage :layer="1" :options="options" title="请选择工资形式" :show="show" @change="change"
					@cancel="cancel"></fui-picker>
			</fui-form-item>

			<fui-form-item :padding='["30rpx",0]' bottomBorder label="工资金额:">
				<fui-input size="26" type="number" v-model="formData.wages" :borderBottom="false" :padding="[0]"
					placeholder="请输入工资金额"></fui-input>
			</fui-form-item>
			<fui-form-item :padding='["30rpx",0]' bottomBorder label="工作时长:">
				<fui-input size="26" type="number" v-model="formData.duration" :borderBottom="false" :padding="[0]"
					placeholder="请输入工作时长"></fui-input>
			</fui-form-item>
			<fui-form-item :padding='["30rpx",0]' bottomBorder label="工作期长:">
				<view class="" @click="dataShow=true">
					<fui-input size="26" v-model="formData.cycle" disabled :borderBottom="false" @click="dataShow=true"
						:padding="[0]" placeholder="请选择工作期长"></fui-input>
				</view>
				<fui-date-picker range :show="dataShow" type="3" @change="dataChange"
					@cancel="dataCancel"></fui-date-picker>
			</fui-form-item>
			<fui-form-item :padding='["30rpx",0]' bottomBorder label="报到日期:">
				<fui-input size="26" disabled :borderBottom="false" @click="reportShow=true" :padding="[0]"
					placeholder="请选择报道日期" v-model="formData.report"></fui-input>
				<fui-date-picker :show="reportShow" type="3" @change="reportChange"
					@cancel="reportCancel"></fui-date-picker>
			</fui-form-item>
			<fui-form-item :padding='["30rpx",0]' bottomBorder label="环境照片:">
				<template v-slot:vertical>
					<view style="width: 100%;">
						<fui-upload immediate :url="urlImg" ref="imgUpload" @delete="imgDelete" @success="imgSuccess"
							@error="error" :fileList="formData.uploadFiles" @complete="complete"></fui-upload>
					</view>
				</template>
			</fui-form-item>
			<fui-form-item :padding='["30rpx",0]' bottomBorder label="环境视频:">
				<template v-slot:vertical>
					<view style="width: 100%;">
						<fui-upload-video immediate :url="urlVideo" ref="videoUpload" @delete="videoDelete"
							@success="videoSuccess" @error="error" :fileList="formData.media"
							@complete="complete"></fui-upload-video>

					</view>
				</template>
			</fui-form-item>
			<fui-form-item :padding='["30rpx"," 0rpx","100rpx","0rpx"]' :bottomBorder="false" label="是否有转发奖励:">
				<fui-radio-group name="radio" @change="checked">
					<view class="fui-list__item flex">
						<view class="fui-align__center">
							<fui-radio color="#FFDD00" :value="0" :checked="formData.rewards==0"></fui-radio>
							<text class="fui-text">没有</text>
						</view>
						<view class="fui-align__center">
							<fui-radio color="#FFDD00" :value="1" :checked="formData.rewards==1"></fui-radio>
							<text class="fui-text">有</text>
						</view>

					</view>
				</fui-radio-group>

			</fui-form-item>
			<fui-form-item :padding='["30rpx"," 0rpx","100rpx","0rpx"]' :bottomBorder="false" label="转发奖励:"
				v-if="formData.rewards==1">
				<view class="flex" style="justify-content: space-between;">
					<view class="flex" style="width: 48%;">
						<fui-input size="26" :borderBottom="false" :padding="['20rpx','0rpx']" type="number"
							placeholder="请输入"><text>币/浏览</text></fui-input>
					</view>
					<view class="flex" style="width: 48%;">
						<fui-input size="26" :borderBottom="false" :padding="['20rpx','0rpx']" type="number"
							placeholder="请输入"><text>币/成交</text></fui-input>
					</view>
				</view>
			</fui-form-item>

		</fui-form>
		<view class="saveBtns">
			<view style="width: 90vw; display: inline-block;">
				<fui-button background="#FFDD00" width="100%" height="70rpx" color="#000" class="saveBtn"
					@click="submitOrder">提交发布</fui-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				formData: {
					cycle: '',
					wages: null,
					wagesType: '',
					nature: '',
					title: '',
					formOrder: 'recruit',
					rewards: 0, //是否有转发奖励
					bargain: 0, //成交
					browse: 0, //浏览
					media: [],
					uploadFiles: [],
					descr: '',
				},
				reportShow: false,
				dataShow: false,
				gender: 0,
				show: false,
				options: [{
					text: '小时工',
					value: 1
				}, {
					text: '日结',
					value: 2
				}, {
					text: '月薪',
					value: 3
				}, {
					text: '年薪',
					value: 4
				}],

				//上传接口地址
				urlImg: 'https://api.zhanfang.comdns.cn/uniapp/common/Upload/upload?file=uniapp&type=image',
				urlVideo: 'https://api.zhanfang.comdns.cn/uniapp/common/Upload/upload?file=uniapp&type=video',
				//上传状态，用于保存或其他操作时做判断
				status: '',
				//上传的视频地址列表
				imgUrls: [],
				videoUrls: [],
				form: null,
				imgUpload: null,
				videoUpload: null,
			};
		},
		methods: {
			reportChange(e) {
				this.reportShow = false
				console.log(e)

				this.formData.report = e.result
			},
			reportCancel() {
				this.reportShow = false
			},
			dataChange(e) {
				this.dataShow = false
				console.log(e)

				this.formData.cycle = `${e.startDate.result} 至 ${e.endDate.result}`
			},
			dataCancel() {
				this.dataShow = false
			},
			change(e) {
				this.show = false
				this.formData.wagesType = e.text
				console.log(e)
			},
			cancel() {
				this.show = false
			},



			submitOrder() {
				console.log('表单', this.formData);
				// wages: null,
				// wagesType: '',
				// cycle:'',
				// title:'',
				// nature: '',
				// formOrder: 'recruit',
				// rewards: 0, //是否有转发奖励
				// bargain: 0, //成交
				// browse: 0, //浏览
				// media: [],
				// uploadFiles: [],
				// descr: '',

				if (!this.formData.title) {
					this.$common.showToast("请输入招聘标题");
					return
				}

				if (!this.formData.descr) {
					this.$common.showToast("请输入招聘详细描述");
					return
				}
				if (!this.formData.nature) {
					this.$common.showToast("请输入招聘性质");
					return
				}

				if (!this.formData.wagesType) {
					this.$common.showToast("请选择工资形式");
					return
				}
				if (!this.formData.wages) {
					this.$common.showToast("请输入工资");
					return
				}

				if (!this.formData.wages) {
					this.$common.showToast("请输入工作时长");
					return
				}

				if (!this.formData.cycle) {
					this.$common.showToast("请输入工作期长");
					return
				}

				if (!this.formData.report) {
					this.$common.showToast("请输入报到日期");
					return
				}


				this.$httpost('/Form/submitOrder', this.formData).then(res => {
					this.$common.showToast("招聘发布成功");
					setTimeout(() => {
						uni.navigateBack({
							delta: 1
						});
					}, 500)
				})
			},
			//图片
			imgSuccess(e) {
				console.log(e)
				let res = JSON.parse(e.res.data.replace(/\ufeff/g, "") || "{}")
				this.status = e.status
				if (res.data.url) {
					this.formData.uploadFiles.push(res.data.url)
				}
			},

			//选择视频或上传完成时触发
			videoDelete(e) {
				this.formData.media.splice(e.index, 1)
			},
			//选择视频或上传完成时触发
			imgDelete(e) {
				this.formData.uploadFiles.splice(e.index, 1)
			},

			// 视频
			videoSuccess(e) {
				console.log(e)
				//e.res 为服务器返回数据
				//上传成功回调，处理服务器返回数据【此处根据实际返回数据进行处理】
				let res = JSON.parse(e.res.data.replace(/\ufeff/g, "") || "{}")
				this.status = e.status
				if (res.data.url) {
					//处理结果返回给组件 
					//res.data.url为上传成功后返回的视频地址
					//e.index为视频索引值
					this.formData.media.push(res.data.url)


				}
			},
			//上传失败时触发
			error(e) {
				this.status = e.status
				uni.showToast({
					title: '上传失败，请检查网络',
					icon: 'fail',
					duration: 2000
				});
			},
			//选择视频或上传完成时触发
			complete(e) {
				this.status = e.status
			},
			checked(e) {
				this.formData.rewards = e.detail.value

			},
			onFormSubmit(e) {
				this.formData = e.detail.value
				console.log('this.formData', this.formData);

			},
			onFormReset(e) {
				this.formData = {}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.saveBtns {
		position: fixed;
		z-index: 100;
		bottom: 20rpx;
		left: 0%;
		right: 0%;
		text-align: center;
	}

	.fui-align__center {
		margin-right: 20rpx;
		display: flex;
		align-items: center;
	}

	.fui-text {
		margin-left: 10rpx;
	}

	::v-deep .fui-uploadv__del-wrap {
		width: 100% !important;
		margin: 0 0 0 0 !important;
	}

	::v-deep .fui-uploadv__item {
		width: 100% !important;
		margin: 0 0 0 0 !important;
	}

	::v-deep .fui-upload__video {
		width: 100% !important;
		margin: 0 0 0 0 !important;
	}

	.uni-form-item {
		padding: 15px 0;
	}

	.title {
		margin-bottom: 10px;
	}

	.group-item {
		flex-direction: row;
		margin-right: 20px;
	}

	.btn {
		flex: 1;
	}

	.btn-submit {
		margin-right: 5px;
	}

	.btn-reset {
		margin-left: 5px;
	}

	.result {
		margin-top: 30px;
	}

	.formItem {
		background-color: white;
		padding: 20rpx;
	}
</style>